import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

class WlistPage extends StatefulWidget {
  final List<Widget> children;
  final int column;
  WlistPage({
    this.children,
    this.column,
  });
  @override
  State<StatefulWidget> createState() => new WlistPageState();
}

class WlistPageState extends State<WlistPage> {
  Widget listDom() {
    return new Expanded(
        flex: 1,
        child: Container(
          margin: EdgeInsets.only(left: 7.5, right: 7.5, bottom: 7.5, top: 7.5),
          child: new Column(
            children: <Widget>[
              new Container(
                height: 200.0,
                child: new Stack(
                  children: <Widget>[
                    new Material(
                      borderRadius: BorderRadius.all(Radius.circular(8.0)),
                      child: new Image.network(
                        'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=4097200241,3195669789&fm=26&gp=0.jpg',
                        fit: BoxFit.fill,
                        height: 200.0,
                      ),
                    ),
                    new Container(
                      margin: EdgeInsets.only(top: 170.0),
                      height: 30.0,
                      child:  new Material(
                        color: Color.fromRGBO(14, 14, 14, 0.51),
                        child: new Row(children: <Widget>[
                          new Expanded(
                            flex: 1,
                            child: new Container(
                              padding: EdgeInsets.only(left: 10.0),
                              child: new Row(
                                children: <Widget>[
                                  new Icon(
                                    Icons.category,
                                    color: Colors.white,
                                    size: 12.0,
                                  ),
                                  new Container(
                                    width: 5.0,
                                  ),
                                  new Text(
                                    '动作片',
                                    style: new TextStyle(
                                        color: Colors.white, fontSize: 12.0),
                                  )
                                ],
                              ),
                            ),
                          ),
                          new Expanded(
                            flex: 1,
                            child: new Container(
                                padding: EdgeInsets.only(right: 10.0),
                                child: new Row(
                                  mainAxisAlignment: MainAxisAlignment.end,
                                  children: <Widget>[
                                    new Icon(
                                      Icons.visibility,
                                      color: Colors.white,
                                      size: 12.0,
                                    ),
                                    new Container(
                                      width: 5.0,
                                    ),
                                    new Text(
                                      '1015',
                                      style: new TextStyle(
                                          color: Colors.white, fontSize: 12.0),
                                    )
                                  ],
                                )),
                          ),
                        ]),
                        borderRadius: BorderRadius.only(
                            bottomLeft: Radius.circular(8.0),
                            bottomRight: Radius.circular(8.0),
                            topLeft: Radius.circular(0.0),
                            topRight: Radius.circular(0.0)),
                      ),
                    ),
                  ],
                ),
                decoration: new BoxDecoration(
//                  border: Border.all(
//                      width: 1.0, color: Color.fromRGBO(239, 239, 239, 1.0)),
                  color: Colors.blue,
                  borderRadius: BorderRadius.all(Radius.circular(8.0)),
//                  image: new DecorationImage(
//                    image: new NetworkImage(
//                        'https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=4097200241,3195669789&fm=26&gp=0.jpg'),
//                    fit: BoxFit.cover,
//                  ),
                ),
              ),
              new Container(

                height: 40.0,
                child: new ListTile(
                  title: new Text(
                    '倩女幽魂3：道道道道道道道道道',
                    maxLines: 1,
//                    textAlign: TextAlign.center,
                    style: new TextStyle(fontSize: 16.0),
                  ),
//                  subtitle: new Text('收账不成，无处可归'),
                ),
              )
            ],
          ),
        ));
  }

  Widget listDomEmpty() {
    return new Expanded(
      flex: 1,
      child: Container(
        margin: EdgeInsets.only(left: 7.5, right: 7.5, bottom: 7.5, top: 7.5),

      ),
    );
  }

  RowDom<Widget>(list) {
    return new Row(
      children: list,
    );
  }
  List<Widget> childrenRow=[];
  List<Widget> list = <Widget>[];
  List<Widget> lists = <Widget>[];
  listTemp<List>(count) {
    var col = widget.column; //每行显示三个
    var countCol = 0; //总行数
    var fillRow = 0; //不足一行填充剩个数

    for (var i = 0; i < count; i++) {
      var isP = true;
      if (i % 2 == 0) {
        isP = false;
      }
      list.add(widget.children[i]);
    }
    countCol = (list.length / col).ceil();
    fillRow = (countCol * col) - list.length;
    for (var i = 0; i < fillRow; i++) {
      list.add(listDomEmpty());
    }
    while (true) {
      var news = list.getRange(0, col);
      lists.add(RowDom(news.toList()));
      list.removeRange(0, col);
      if (list.length == 0) {
        break;
      }
    }
    return lists;
  }
  @override
  initState(){
    setState(() {
    
    });
    if(widget.children.length>0){
      childrenRow=listTemp(widget.children.length);
    }
  }

  @override
  dispose(){
    lists.clear();
    list.clear();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      margin: EdgeInsets.only(left: 7.5, right: 7.5, top: 0.0, bottom: 7.5),
      child: new Column(
        children: childrenRow,
      ),
    );
  }
}
